package loss;

/**
 * LogLinear Loss Function
 * @author tigerzhong
 *
 */
public class LogLinear implements LossFun{

    @Override
    public double[] getGradient(double prediction, double[] instance, double target) {
	int len = instance.length;
	double dev[] = new double[len];
	for(int i=0;i<len;i++){
	    dev[i] = target / prediction * instance[i] - instance[i];
	}
	return dev;
    }

    @Override
    public double getLoss(double prediction, double target) {
	return (target * Math.log(prediction) - prediction);
    }

}
